// HSS.Forms.DataGridViewCalendarCell.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       DataGridViewCalendarCell.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   12/04/2010
// ----------------------------------------------------------------------------
namespace HSS.Forms
{
	#region Using Directives
	using System;
	using System.Windows.Forms;
	#endregion

	#region DataGridViewCalendarCell
	/// <summary>
	/// A DataGridView CalendarCell
	/// </summary>
	public class DataGridViewCalendarCell : DataGridViewTextBoxCell
	{
		/// <summary>
		/// Default Constructor
		/// </summary>
		public DataGridViewCalendarCell()
			: base()
		{
			// Use the short date format.
			this.Style.Format = "d";
		}

		/// <summary>
		/// Initializes the Editing Control
		/// </summary>
		/// <param name="rowIndex">The Index of the Row being edited</param>
		/// <param name="initialFormattedValue">The inital value</param>
		/// <param name="dataGridViewCellStyle">The Cell Style</param>
		public override void InitializeEditingControl(int rowIndex, object
			initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
		{
			if (null == this.Value)
			{
				this.Value = DateTime.Now;
			}
			// Set the value of the editing control to the current cell value.
			base.InitializeEditingControl(rowIndex, initialFormattedValue,
				dataGridViewCellStyle);
			DataGridViewCalendarEditingControl ctl =
				DataGridView.EditingControl as DataGridViewCalendarEditingControl;
			ctl.Value = (DateTime)this.Value;
		}

		/// <summary>
		/// The Editing Type
		/// </summary>
		/// <remarks>
		/// <para>
		/// Return the type of the editing contol that the DataGridViewCalendarCell uses.
		/// </para>
		/// <para>
		/// The editing contol is always a <see cref="DataGridViewCalendarEditingControl"/> Control
		/// </para>
		/// </remarks>
		public override Type EditType
		{
			get
			{
				// Return the type of the editing contol that CalendarCell uses.
				return typeof(DataGridViewCalendarEditingControl);
			}
		}

		/// <summary>
		/// The Value Type
		/// </summary>
		/// <remarks>
		/// Returns a <see cref="System.Type"/> of a <see cref="System.DateTime"/> Type
		/// </remarks>
		public override Type ValueType
		{
			get
			{
				// Return the type of the value that CalendarCell contains.
				return typeof(DateTime);
			}
		}

		/// <summary>
		/// The Default value for a new row
		/// </summary>
		/// <remarks>
		/// Returns the <see cref="System.DateTime.Now"/> Value
		/// </remarks>
		public override object DefaultNewRowValue
		{
			get
			{
				// Use the current date and time as the default value.
				return DateTime.Now;
			}
		}
	}
	#endregion
}